home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / libray / libcommon / memory.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  1.8 KB  |  101 lines

  1. /*
  2.  * memory.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * memory.c,v 4.1 1994/08/09 07:54:53 explorer Exp
  17.  *
  18.  * memory.c,v
  19.  * Revision 4.1  1994/08/09  07:54:53  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:01  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0  91/07/17  14:30:57  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29. #ifdef SYSV
  30. #include <memory.h>
  31. #endif
  32. #include "common.h"
  33.  
  34. unsigned long TotalAllocated;
  35.  
  36. voidstar
  37. Malloc(bytes)
  38. unsigned bytes;
  39. {
  40.     voidstar res;
  41.  
  42.     TotalAllocated += bytes;
  43.  
  44.     res = (voidstar)malloc(bytes);
  45.     if (res == (voidstar)NULL)
  46.         RLerror(RL_PANIC,
  47.             "Out of memory trying to allocate %d bytes.\n",bytes);
  48.     return res;
  49. }
  50.  
  51. voidstar
  52. Calloc(nelem, elen)
  53. unsigned nelem, elen;
  54. {
  55.     voidstar res;
  56.  
  57.     res = Malloc(nelem*elen);
  58.     bzero(res, (int)nelem*elen);
  59.     return res;
  60. }
  61.  
  62. void
  63. PrintMemoryStats(fp)
  64. FILE *fp;
  65. {
  66.     fprintf(fp,"Total memory allocated:\t\t%lu bytes\n",
  67.             TotalAllocated);
  68. }
  69.  
  70. /*
  71.  * Allocate space for a string, copy string into space.
  72.  */
  73. char *
  74. strsave(s)
  75. char *s;
  76. {
  77.     char *tmp;
  78.  
  79.     if (s == (char *)NULL)
  80.         return (char *)NULL;
  81.  
  82.     tmp = (char *)Malloc((unsigned)strlen(s) + 1);
  83.     (void)strcpy(tmp, s);
  84.     return tmp;
  85. }
  86.  
  87. #ifdef MULTIMAX
  88.  
  89. char *
  90. share_calloc(num, siz)
  91. int num;
  92. unsigned int siz;
  93. {
  94.     char *res;
  95.  
  96.     res = share_malloc(num*siz);
  97.     bzero(res, num*siz);
  98.     return res;
  99. }
  100. #endif
  101.